package com.chukun.flink.dataset.operator;

import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;

/**
 * @author chukun
 * @version 1.0.0
 * @description filter 操作符的基本操作
 * @createTime 2022年05月28日 20:35:00
 */
public class FilterOperator {

    public static void main(String[] args) throws Exception {

        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

        DataSource<Long> dataSource = env.generateSequence(1, 5);

        DataSet<Long> filteredData = dataSource.filter(new FilterFunction<Long>() {

            @Override
            public boolean filter(Long value) throws Exception {
                if (value == 1 || value == 2) {
                    return true;
                }
                return false;
            }
        });

        filteredData.print("FilterFunction");

        env.execute("FilterOperator");
    }
}
